<?php
namespace Home\Model;
use \Think\Model\RelationModel;
/*
 * 要使用TP的关联查询效果，必须要要继承自关联模型
 */
class GoodsModel extends RelationModel{
    /**
     * session 记录浏览历史
     * @param $row
     */
    public function history($row) {
        $history = session('?history') ? session('history') : array();
        $g = array();
        $g['goods_name'] = $row['goods_name'];
        $g['thumb_img'] = $row['thumb_img'];
        $g['shop_price'] = $row['shop_price'];
        $history[$row['goods_id']] = $g;
        if(count($history) > 5) {
            $key = key($history);
            unset($history[$key]);
        }
        session('history' ,$history);
}
    
    /**
     * 利用Model的$_link来说明关系.
     * 以商品表goods为例,每条商品在comment表中,有多条评价.
     * 声明如下关系:
     * @var array
     */
    protected $_link = array(
        'comment'=> self::HAS_MANY,
    );
}